package com.comp7940.groupf.tgbot.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class EmailUtil {
    @Autowired
    private JavaMailSender mailSender;
    public void sendSimpleEmail(String to,String subject,String text) {
//        定制纯文本邮件信息SimplemaileMassage
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("212134461@qq.com");//向指定的邮件发送信息
        message.setTo(to);
        message.setSubject(subject);
        message.setText(text);
        try {
            //发送邮件
            mailSender.send(message);
            System.out.println("纯文本邮件发送成功");
        }catch (MailException e) {
            System.out.println("纯文本邮件发送失败"+e.getMessage());
            e.printStackTrace();
        }
    }
}
